<?php
/**
 * ============================================================================
 * Doxt Version: 1.0           杭州多讯科技有限公司
 * Web: http://www.doxt.com
 * Copyright (C) 2007 - 2010 Doxt Technology Inc., All Rights Reserved.
 * ---------------------------------------------
 * $Date: 2008.4.8
*/
  if( ! defined("IN_WEB"))
  {
	   header("location: http://$_SERVER[SERVER_NAME]/siteadmin/index.php");
  }

  $tpl->set_file("page", "expand_cate.htm");
  $tpl->set_block("page","CATE_LIST","cate_list"); 
  
  $query = "SELECT * FROM $TBL_CATE WHERE parent_id='$cPath' ORDER BY cate_order";
  $result = mysql_query( $query) or die(mysql_error());
  while ( $array = mysql_fetch_array( $result))
  {
    $cate_id = $array["cate_id"];

    //如果没有选中分类,则默认选中第一个
	$cID = empty($cID) ? $cate_id : $cID;

	//子类的总数
	$query = "SELECT COUNT(cate_id) FROM $TBL_CATE WHERE parent_id='$cate_id'";
	$son_num = do_query( $query, 3);
	  
	//控制是否可以进入下一级,此处设为2级
	$allow_son = ( ! $allow_son && $array['parent_id'] != 0) ? true : false;

    //选中与未选中的显示方式不同
    if ( $cID == $cate_id)
	{
	  $img_name = "icon_arrow_right.gif";
	  $css_tr = "dataTableRowSelected";
	  $this_cate = $array;   //保存此分类的数据,供work_cate.php调用
	} 
	else
	{
	  $img_name = "icon_info.gif";  
      $css_tr = "dataTableRow";
	}	

	$tpl->set_var(array( 
					 "CATE_CNAME" => stripslashes($array["zh_cate_title"]),
					 "CATE_ENAME" => stripslashes($array["en_cate_title"]),
					 "SORT_ID" => $array["cate_order"],
					 "CATE_ID" => $cate_id,
					 "CSS_TR" => $css_tr,	                                  
		             "VIEW_URL" => "?cID=$cate_id&cPath=$cPath",
					 "EDIT_CATE" => "?cID=$cate_id&cPath=$cPath&mode=edit_cate",
					 "ADD_SON" => "?cPath=$cate_id&mode=add_cate",
					 "SON_URL" => "?cPath=$cate_id",
	                 "IMG_NAME" => $img_name,
					 "C_PATH" => $cPath,
					 "SON_NUM" => $son_num,
	                   ));

    $tpl->parse("cate_list", "CATE_LIST", true);
  }

  //返回按钮
  if ( $cPath != 0 )
  {
    $parent = get_owner_val("parent_id", "cate_id", $cPath, $TBL_CATE); //父类ID
	$return_url = "document.location.href='?cPath=$parent'";
    $tpl->set_block("page", "BLO_RETURN", "blo_return");
	$tpl->set_var("RETURN_URL", $return_url);
	$tpl->parse("blo_return", "BLO_RETURN");
  }
  else
  {   
     $sub_num = get_owner_val("cate_id", "parent_id", $cID, $TBL_CATE, 1);  //子分类的个数
	$tpl->set_block("page", "BLO_RETURN", "blo_return");
  }

  $this_path = empty( $cID) ? $cPath : $cID;
  $tpl->set_var(array(
					"this_path" => get_parent_title( $this_path, "?cID=%s&cPath=%s"),  //生成导航
					"ADD_CATE_URL" => "?cPath=$cPath&mode=add_cate",   //添加分类
					"SUB_NUM" => $sub_num,
					"UNITE_CATE" => "?cPath=$cPath&cID=$cID&mode=unite_cate",
					"MOVE_CATE" => "?cPath=$cPath&cID=$cID&mode=move_cate",
					));

  //返回的路径
  $param = "?cID=$cID&cPath=$cPath";

  $tpl->parse("Output", "page");
  $left_page = $tpl->get("Output");
?>